package log

import (
	"fmt"
	"io"
	"log"
	"os"
)

var glog *log.Logger = nil

func init() {
	glog = log.New(os.Stdout, "info: ", log.Ldate|log.Ltime|log.Lshortfile)
	glog.SetPrefix("proxy: ")
}

//SetOutputPathFile SetOutputPathFile
func SetOutputPathFile(path string) {
	file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalln("Failed to open error log file:", err)
	}
	glog = log.New(io.MultiWriter(file, os.Stdout), "info: ", log.Ldate|log.Ltime|log.Lshortfile)
	glog.SetPrefix("proxy: ")
}

//SetPrefix SetPrefix
func SetPrefix(prefix string) {
	if glog == nil {
		return
	}
	glog.SetPrefix(prefix)
}

//Println debug
func Println(v ...interface{}) {
	if glog == nil {
		return
	}
	glog.Output(2, fmt.Sprintln(v...))
}
